﻿/*
Medion Info Display

Copyright 2010 Wolf Posdorfer,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MD8800.util
{
    /// <summary>
    /// Klasse zum formatieren für die Zeitanzeige
    /// </summary>
    public static class Time
    {

        private static DateTime _now = DateTime.Now;
        private static int _tag;
        private static int _monat;
        private static int _jahr;

        private static int _minute;
        private static int _stunde;
        private static char[] _chartable;

        /// <summary>
        /// gibt die Zeit im richtig formatierten String zurück
        /// </summary>
        /// <returns>richtig formatierter String</returns>
        public static String gibZeit()
        {
            String s = "";
            _tag = _now.Day;
            _monat = _now.Month;
            _jahr = _now.Year;
            _minute = _now.Minute;
            _stunde = _now.Hour;

            // 17:34 24.12.2005
            // Minute Stunde Monat Tag Jahr Jahr // 45 17 12 24 20 10

            _tag = int.Parse("" + _tag, System.Globalization.NumberStyles.HexNumber);
            _monat = int.Parse("" + _monat, System.Globalization.NumberStyles.HexNumber);

            int jahr1 = int.Parse(("" + _jahr).Substring(0, 2)); 
            int jahr2 = int.Parse(("" + _jahr).Substring(2, 2));

            jahr1 = int.Parse("" + jahr1, System.Globalization.NumberStyles.HexNumber);
            jahr2 = int.Parse("" + jahr2, System.Globalization.NumberStyles.HexNumber);

            _minute = int.Parse("" + _minute, System.Globalization.NumberStyles.HexNumber);
            _stunde = int.Parse("" + _stunde, System.Globalization.NumberStyles.HexNumber);

            _chartable = new char[6];
            _chartable[0] = (char)_minute;
            _chartable[1] = (char)_stunde;
            _chartable[2] = (char)_tag;
            _chartable[3] = (char)_monat;
            _chartable[4] = (char)jahr1;
            _chartable[5] = (char)jahr2;

            for (int i = 0; i < _chartable.Length; i++)
            {
                s += _chartable[i];
            }
            return s;

        }

        /// <summary>
        /// gibt die Uhrzeit als String
        /// </summary>
        /// <returns>die jetzige Uhrzeit als String</returns>
        public static String toString()
        {
            return _now.ToString();
        }

        /// <summary>
        /// gibt die einzelnen Bytes des formatierten Uhrzeitstrings
        /// </summary>
        /// <returns>Array of char</returns>
        public static char[] gibChars()
        {
            return _chartable;
        }

        /// <summary>
        /// gibt die aktuelle Minute
        /// </summary>
        public static int getMinute()
        {
            _now = DateTime.Now;
            return _now.Minute;
        }

    }
}
